package com.bytedance.improvingroad

import android.view.View
import androidx.fragment.app.Fragment
import com.bytedance.improvingroad.activity.BaseBindingActivity
import com.bytedance.improvingroad.banner_test.banner_frags.*
import com.bytedance.improvingroad.databinding.ActivityBannerShowBinding

class BannerShowActivity : BaseBindingActivity<ActivityBannerShowBinding>(), View.OnClickListener {

    var changeIndicatorListener: ChangeIndicatorListener? = null
    override fun initListener() {
        binding.AlphaPageTransformer.setOnClickListener(this)
        binding.DepthPageTransformer.setOnClickListener(this)
        binding.MZScaleInTransformer.setOnClickListener(this)
        binding.RotateDownPageTransformer.setOnClickListener(this)
        binding.RotateUpPageTransformer.setOnClickListener(this)
        binding.RotateYTransformer.setOnClickListener(this)
        binding.ScaleInTransformer.setOnClickListener(this)
        binding.ZoomOutPageTransformer.setOnClickListener(this)
        binding.RectangleIndicator.setOnClickListener(this)
        binding.RoundLinesIndicator.setOnClickListener(this)
        binding.DrawableIndicator.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        when(v?.id) {
            R.id.AlphaPageTransformer-> {
                replaceFragment(AlphaFragment())
            }
            R.id.DepthPageTransformer-> {
                replaceFragment(DepthFragment())
            }
            R.id.MZScaleInTransformer-> {
                replaceFragment(MZScaleFragment())
            }
            R.id.RotateDownPageTransformer-> {
                replaceFragment(RotateDownFragment())
            }
            R.id.RotateUpPageTransformer-> {
                replaceFragment(RotateUpFragment())
            }
            R.id.RotateYTransformer-> {
                replaceFragment(RotateYFragment())
            }
            R.id.ScaleInTransformer-> {
                replaceFragment(ScaleInFragment())
            }
            R.id.ZoomOutPageTransformer-> {
                replaceFragment(ZoomOutFragment())
            }
            R.id.RoundLinesIndicator -> changeIndicatorListener?.changeIndicator(IndicatorVFragment.ROUND_LINE)
            R.id.RectangleIndicator -> changeIndicatorListener?.changeIndicator(IndicatorVFragment.ROUND_RECT)
        }
    }

    private fun replaceFragment(fragment: Fragment) {
        supportFragmentManager.beginTransaction()
            .replace(binding.bannerContainer.id,fragment)
            .commit()
    }

    override fun initData() {
        supportFragmentManager.beginTransaction()
            .add(binding.bannerContainer.id,IndicatorVFragment())
            .commit()
    }

    interface ChangeIndicatorListener{
        fun changeIndicator(type: Int)
    }
}